/*
 *       This file is part of VFC.
 *
 *        VFC is free software: you can redistribute it and/or modify
 *        it under the terms of the GNU General Public License as published by
 *        the Free Software Foundation, either version 3 of the License, or
 *        (at your option) any later version.
 *
 *        VFC is distributed in the hope that it will be useful,
 *        but WITHOUT ANY WARRANTY; without even the implied warranty of
 *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *        GNU General Public License for more details.
 *
 *        You should have received a copy of the GNU General Public License
 *        along with VFC.  If not, see <http://www.gnu.org/licenses/>.
 */


using System;
using System.Collections.Generic;
using System.Text;

namespace VFC.Nes.Cpu.Opcode
{
    class Accumulator
    {
        private static int tmp = 0;

        public static void ASL()
        {
            if ((Cpu.Register.A >> 7) == 1)
            {
                Cpu.Register.SetCarryFlag();
            }
            else
            {
                Cpu.Register.ClearCarryFlag();
            }
            tmp = Cpu.Register.A << 1;
            Cpu.Register.A = tmp & 0xff;
            Flags.CheckForZeroFlag(Cpu.Register.A);
            Flags.CheckForNegativeFlag(Cpu.Register.A);
            Cpu.Register.PC += Cpu.Core.Size[Cpu.Core._Opcode_];
        }

        public static void LSR()
        {
            if ((Cpu.Register.A & 0x01) == 1)
            {
                Cpu.Register.SetCarryFlag();
            }
            else
            {
                Cpu.Register.ClearCarryFlag();
            }
            Cpu.Register.A >>= 1;
            Flags.CheckForZeroFlag(Cpu.Register.A);
            Flags.CheckForNegativeFlag(Cpu.Register.A);
            Cpu.Register.PC += Cpu.Core.Size[Cpu.Core._Opcode_];
        }

        public static void ROL()
        {
            tmp = ((Cpu.Register.A << 1) | (Cpu.Register.GetCarryFlag() == 1 ? 1 : 0)) & 0xff;
            if ((Cpu.Register.A & 0x80) == 0x80)
            {
                Cpu.Register.SetCarryFlag();
            }
            else
            {
                Cpu.Register.ClearCarryFlag();
            }
            Cpu.Register.A = tmp;
            Flags.CheckForZeroFlag(Cpu.Register.A);
            Flags.CheckForNegativeFlag(Cpu.Register.A);
            Cpu.Register.PC += Cpu.Core.Size[Cpu.Core._Opcode_];
        }

        public static void ROR()
        {
            tmp = ((Cpu.Register.A >> 1) | (Cpu.Register.GetCarryFlag() == 1 ? 0x80 : 0)) & 0xff;
            if ((Cpu.Register.A & 0x01) == 0x01)
            {
                Cpu.Register.SetCarryFlag();
            }
            else
            {
                Cpu.Register.ClearCarryFlag();
            }
            Cpu.Register.A = tmp;
            Flags.CheckForZeroFlag(Cpu.Register.A);
            Flags.CheckForNegativeFlag(Cpu.Register.A);
            Cpu.Register.PC += Cpu.Core.Size[Cpu.Core._Opcode_];
        }
    }
}
